home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Nuntius 1.2 / src / Nuntius / UBinDecoders.h < prev    next >
Encoding:
Text File  |  1994-02-20  |  2.1 KB  |  91 lines  |  [TEXT/MPS ]

  1. // Copyright © 1993 Peter Speck (speck@dat.ruc.dk).  All rights reserved.
  2. // UBinDecoders.h
  3.  
  4. #ifndef __UPTROBJECT__
  5. #include "UPtrObject.h"
  6. #endif
  7.  
  8.  
  9. const long kOutBufferSize = 4 * 1024;
  10.  
  11. class PBinaryDecoder : public PPtrObject
  12. {
  13.     public:
  14.         virtual void DecodeLine(const CStr255 &line) = 0;
  15.         virtual Boolean IsDoneNow() = 0;
  16.         virtual void PostProcess();
  17.         virtual void Abort();
  18.         
  19.         PBinaryDecoder();
  20.         void IBinaryDecoder(TFile *outFile);
  21.         ~PBinaryDecoder();
  22.     protected:
  23.         TFile *fFile;
  24.         ParamBlockRec fPB;
  25.         
  26.         void OpenFork(Boolean dataFork); // for rsrc: will act as raw data fork in fFile 
  27.         void CloseFork();
  28.         void WriteBytes(const void *p, long noBytes);
  29.     private:
  30.         Ptr fOutBufferP, fOutBufferPosP;
  31.         long fBytesFreeInOutBuffer;
  32.         
  33.         void FlushOutBuffer();
  34. };
  35.  
  36.  
  37. class PUUDecoder : public PBinaryDecoder
  38. {
  39.     public:
  40.         void DecodeLine(const CStr255 &line);
  41.         Boolean IsDoneNow();
  42.         void PostProcess();
  43.         void PrepareUU();
  44.  
  45.         PUUDecoder();
  46.         void IUUDecoder(TFile *outFile);
  47.         ~PUUDecoder();
  48.     private:
  49.         enum {kInsideIt, kWaitForDelim, kAtEnd} fState;
  50.         Boolean fGotUUDelemiter;
  51.         Boolean fFirstUULineInBlock;
  52.         
  53.         void ProcessLine(CStr255 &text);
  54.         Boolean IsValidUUEncodeLine(CStr255 &text);
  55. };
  56.  
  57. const kBinHexBinaryBufferSize = 4 * 1024;
  58. class PBinHexDecoder : public PBinaryDecoder
  59. {
  60.     public:
  61.         void DecodeLine(const CStr255 &line);
  62.         Boolean IsDoneNow();
  63.         void PostProcess();
  64.  
  65.         PBinHexDecoder();
  66.         void IBinHexDecoder(TFile *outFile);
  67.         ~PBinHexDecoder();
  68.     private:
  69.         enum {kAtStart, kAtEnd, kWaitForStartColon, kInsideIt, kWaitForDelim} fAsciiState;
  70.         enum {kInHeader, kInDataFork, kInRsrcForm, kPastEnd} fBinaryState;
  71.         
  72.         short f6To8Index;
  73.         char fAcc, fLastChar;
  74.         Boolean fRunFlag;
  75.         void ProcessAsciiLine(char *p);
  76.         void ProcessAsciiChar(unsigned char ch);
  77.         //
  78.         Ptr fBinaryBufferP, fBinaryBufferPosP;
  79.         long fBytesInBinaryBuffer;
  80.         void StoreBinaryChar(unsigned char ch);
  81.         void EatenBinaryData(long noBytes);
  82.         //
  83.         unsigned short fFinderFlags;
  84.         long fDataLen, fRsrcLen;
  85.         short fCRC;
  86.         long fForkBytesLeft;
  87.         Boolean ProcessHeaderData();
  88.         Boolean ProcessForkData();
  89.         void CalcCRC(const void *p, long noBytes);
  90.         void CheckCRC();
  91. };